package org.ztr.saa01helloword.config;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/9/24 21:31
 * @Description: 配置类
 * @Version: 1.0
 */
@Configuration
public class SaaLLMConfig {
    private static final Logger logger = LogManager.getLogger(SaaLLMConfig.class);

    @Value("${spring.ai.dashscope.api-key}")
    private String apiKey;

    // 从配置文件读取apiKey
//    @Bean
//    public DashScopeApi dashScopeApi(){
//        return DashScopeApi.builder()
//                .apiKey(apiKey)
//                .build();
//    }

    // 从系统环境变量读取apiKey
    @Bean
    public DashScopeApi dashScopeApi(){
        return DashScopeApi.builder()
                .apiKey(System.getenv("aiQwen-apikey"))
                .build();
    }
}
